import sympy as sp
from sympy import integrate, Integral

# 定义符号变量
x, y = sp.symbols('x y')

# 不定积分
f = x**2 + 2*x + 1
integral = integrate(f, x)
print("不定积分:", integral) # 不定积分: x**3/3 + x**2 + x

# 定积分
definite_integral = integrate(f, (x, 0, 1))
print("定积分:", definite_integral) # 定积分: 7/3

# 多重积分
double_integral = integrate(x*y, (x, 0, 1), (y, 0, 1))
print("二重积分:", double_integral) # 二重积分: 1/4

# 创建积分表达式但不立即计算
integral_expr = Integral(f, x)
print("积分表达式:", integral_expr) # 积分表达式: Integral(x**2 + 2*x + 1, x)
print("计算积分:", integral_expr.doit()) # 计算积分: x**3/3 + x**2 + x